package com.jin.lazytool.entity;

import com.jin.lazytool.componment.NumberField;
import com.jin.lazytool.utils.JinUtils;
import javafx.scene.control.Label;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import org.luaj.vm2.LuaTable;

import java.awt.*;

public class SleepEvent extends IEvent{


    @Override
    public int execute(Robot robot, int index) throws InterruptedException,NoSuchMethodException {
        if(luaFLag){
            LuaTable lua = JinUtils.evalLua(getLua(), getTime());
            boolean exeFlag = lua.get("exeFlag").toboolean();
            if(exeFlag){
                Thread.sleep(lua.get("time").tolong());
            }
        }else{
            Thread.sleep(getTime());
        }
        return index;
    }

    @Override
    public Pane initDesc() {
        FlowPane pane = new FlowPane();
        pane.setStyle("-fx-pref-height: 26;");
        Label label = new Label("等待: ");
        label.setTextFill(Color.GRAY);
        NumberField field = new NumberField();
        field.editableProperty().set(false);
        field.setValue(getTime());
        pane.getChildren().addAll(label, field);
        return pane;
    }

    @Override
    void show() {

    }
}
